package com.example.my_self_view.list

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.example.my_self_view.databinding.ItemProvinceListBinding

/**
 * @dsc     简介
 * @Author  LiWeiZhong
 * @Date    2025/1/20 10:39
 * @Version 1.0
 */
class ProvinceListAdapter: BaseAdapter<Item, ItemProvinceListBinding>() {
    override fun getVB(inflater: LayoutInflater, parent: ViewGroup): ItemProvinceListBinding {
        return ItemProvinceListBinding.inflate(inflater, parent, false)
    }

    override fun addEventListener(holder: Holder) {

    }

    override fun onBindHolder(holder: Holder, position: Int) {
        getData(position).apply {
            when (type) {
                Item.Type.TITLE -> {
                    if (this is Letter) {
                        val letter = this

                        holder.mBinding.letter.visibility = View.VISIBLE
                        holder.mBinding.province.visibility = View.GONE

                        holder.mBinding.letter.text = letter.value
                    }
                }
                Item.Type.CONTENT -> {
                    if (this is Province) {
                        val province = this

                        holder.mBinding.letter.visibility = View.GONE
                        holder.mBinding.province.visibility = View.VISIBLE

                        holder.mBinding.province.text = province.name
                    }
                }
            }
        }
    }
}